package vista;

import controlador.UsuarioJpaController;
import controlador.conexionMySql;
import java.io.IOException;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import modelo.Usuario;

@ManagedBean
@SessionScoped
public class loginBean {

    private String username;
    private String password;
    private conexionMySql sql = new conexionMySql();
    private Usuario other = new Usuario();
    private UsuarioJpaController daou = new UsuarioJpaController();

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String login() throws IOException {

        String login = "invalido";
        other = daou.findUser(username);

        if (other != null && other.getUsuario().equals(username) && other.getContrasenia().equals(password)) {
            login = other.getRol();
        }
        System.out.println(login);
        return login;
    }

    public boolean isLoggedIn() {
        return other != null;
    }
}
